'''
    编写程序,按用户输入的半径计算圆的面积,若半径为负值则抛出异常(圆的面积公式:S=πr²)
'''
import math
class RadiusNumberError(Exception):
    def __init__(self,radius):
        self.radius = radius
    def __str__(self):
        return f'半径不能为负值,你输入的值为{self.radius}'

def area_calc():
    radius = float(input('请输入圆的半径'))
    try:
        area = math.pi*radius**2
        if radius < 0:
            raise RadiusNumberError(radius)
    except RadiusNumberError as e:
        print(e)
    else:
        print(f'圆的面积为{area}')
    finally:
        print('计算完毕')

area_calc()

